package com.mtl.inmigrant.shoes.adapter;

import java.util.List;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.TextView;

import com.mtl.inmigrant.shoes.R;

public class GPlusActivityAdapter  extends ArrayAdapter<com.google.api.services.plus.model.Activity> {
	
	private final List<com.google.api.services.plus.model.Activity> list;
	private LayoutInflater inflator;

	public GPlusActivityAdapter(Activity context,
			List<com.google.api.services.plus.model.Activity> list) {
		super(context, R.layout.activities_list, list);
		inflator = context.getLayoutInflater();
		this.list = list;
	}

	static class ViewHolder {
		protected TextView text;
		protected CheckBox checkbox;
		
		public String toString(){
			return text.getText().toString();	
		}
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder viewHolder;
		com.google.api.services.plus.model.Activity gPlusActivity = (com.google.api.services.plus.model.Activity) this.getItem( position );   
		if (convertView == null) {

			convertView = inflator.inflate(R.layout.activities_list, parent, false);
			viewHolder = new ViewHolder();
			viewHolder.text = (TextView) convertView.findViewById(R.id.label);
			viewHolder.checkbox = (CheckBox) convertView.findViewById(R.id.check);
			
			viewHolder.text.setTag(gPlusActivity);
			viewHolder.checkbox.setTag(gPlusActivity);
			
			convertView.setTag(viewHolder);
				
		} else {
			viewHolder = (ViewHolder) convertView.getTag();	 
		}
		
		viewHolder.text.setText(gPlusActivity.getTitle());
		viewHolder.checkbox.setChecked(false);
		return convertView;
	}

}
